/* 
 * File:   RenderingSystem.h
 * Author: aljosa
 *
 * Created on April 28, 2010, 11:19 PM
 */

#ifndef _RENDERINGSYSTEM_H
#define	_RENDERINGSYSTEM_H

// Includes
#include "Vector3.h"
#include "Render_Box2D.h"

// OpenGL includes
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>

//
#include "Terrain.h"

// Defines
#define DEG2RAD 0.017453278

#define PI 3.14159265
#define PI2 (PI*2)

// Basic colors
#define RED 1.0, 0.0, 0.0
#define GREEN 0.0, 1.0, 0.0
#define BLUE 0.0, 0.0, 1.0
#define WHITE 1.0, 1.0, 1.0
#define BLACK 0.0, 0.0, 0.0

using namespace xEngine::PlatformIndependent::Math; // We need math stuff here

//
//
// __TODO__:
// CLEAN THIS MESS
//
//

namespace xEngine
{
    //
    // RenderingSystem singleton
    //
    namespace Renderer
    {
        using namespace Resources;

        class RenderingSystem {
        public:
            // Constructor, Destructor
            //
            ~RenderingSystem();

            // Instance getter
            static RenderingSystem* get(); // Get the only instance of the class


            // System init and shutdown
            bool init();
            void shutDown();

            // Actual interface
            //
            // TODO: REFACTOR!!!!
            //

            // Draw stuff methods
            void drawDot(const Vector3 &p);
            void drawCircle(const Vector3 &p, double r, unsigned tris);

            void drawCube(const Vector3 &p);
            void drawSphere(const Vector3 &p, int segments, int slices, double radius);
            //void drawLightwaveModel(const Vector3 &p, CLWObject *lwo);
            void drawBackground();
            void drawSkyCube(float x, float y, float z, float size, int textures[6]);
   //         void drawCube(float x, float y, float size, float *color, int texID);
   //         void drawFloor(float x, float y, float size, float *color, int texID);
            //void drawLightwaveModel(float x, float y, float z, LWObject *lwo);

            void drawTerrain(const Vector3 &p, const Terrain &terrain); // Draw terrain at position p

            // xTo methods
            void moveTo(Vector3 p);
            void lineTo(Vector3 p);

            Vector3 windowToOpenGLCoords(int x, int y);


            //
            // INLINE methods
            //

            // Sets color
            // Param: Vector 4x1
            inline void setColor(const float *color)
            {
                glColor4f(color[0], color[1], color[2], color[3]);
            }

            // Rendering state modifiers
            inline void setWireMode()
            {
                glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
            }

            inline void setPolygonMode()
            {
                glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
            }

            // Blending ON/OFF
            inline void setEnableBlending()
            {
                glEnable(GL_BLEND);
            }

            inline void setDisableBlending()
            {
                glDisable(GL_BLEND);
            }

            // Public class members
            DebugDraw Box2DRender;

        protected:
            RenderingSystem();

        private:
            Vector3 currentPos; // For x_to functions (example: lineTo)
            static RenderingSystem *instance; // The only singleton instance

        };


    }
}



#endif	/* _RENDERINGSYSTEM_H */

